package com.gjy.util.sb.util;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.stereotype.Component;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2023-10-24 09:15:03
 */
@Component
public class BeanFactoryUtil implements BeanFactoryPostProcessor {

    private static ConfigurableListableBeanFactory factory;

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
        BeanFactoryUtil.factory = beanFactory;
    }

    public static <T> T getBean(Class<T> cls) {
        return factory.getBean(cls);
    }

}
